<?php

namespace common\models\mdm;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\mdm\MdmPosition;

/**
 * MdmPositionSearch represents the model behind the search form about `common\models\mdm\MdmPosition`.
 */
class MdmPositionSearch extends MdmPosition
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['PK_ORG', 'PK_GROUP', 'PK_ORG_V', 'PK_POST', 'CREATOR', 'CREATIONTIME', 'MODIFIER', 'MODIFIEDTIME', 'VAPPROVEID', 'DAPPROVEDATE', 'VAPPROVENOTE', 'BILLCODE', 'TRANSTYPE', 'TRANSTYPEID', 'PK_BILLTYPE', 'PK_BUSITYPE', 'PK_DEF1', 'PK_DEF2', 'PK_DEF3', 'PK_DEF4', 'PK_DEF5', 'VVDEF1', 'VVDEF2', 'VVDEF3', 'VVDEF4', 'VVDEF5', 'VVDEF6', 'VVDEF7', 'VVDEF8', 'VVDEF9', 'VVDEF10', 'VVDEF11', 'VVDEF12', 'VVDEF13', 'VVDEF14', 'VVDEF15', 'DDEF1', 'DDEF2', 'DDEF3', 'DDEF4', 'DDEF5', 'BDEF1', 'BDEF2', 'BDEF3', 'BDEF4', 'BDEF5', 'POSTCODE', 'POSTNAME', 'POSTTYPE', 'STARTDATE', 'RZTJZG', 'POSTDUTY', 'POSTRANK', 'WORKSTANDARD', 'KEYDUTYRANK', 'ISNOTUSE', 'NOTUSEDATE', 'NOTUSEMAN', 'SSORG', 'TS'], 'safe'],
            [['BILLSTATUS', 'IDEF1', 'IDEF2', 'IDEF3', 'IDEF4', 'IDEF5', 'POSTYDRSCOUNT', 'POSTSDRSCOUNT', 'DR'], 'integer'],
            [['NDEF1', 'NDEF2', 'NDEF3', 'NDEF4', 'NDEF5'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = MdmPosition::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'BILLSTATUS' => $this->BILLSTATUS,
            'IDEF1' => $this->IDEF1,
            'IDEF2' => $this->IDEF2,
            'IDEF3' => $this->IDEF3,
            'IDEF4' => $this->IDEF4,
            'IDEF5' => $this->IDEF5,
            'NDEF1' => $this->NDEF1,
            'NDEF2' => $this->NDEF2,
            'NDEF3' => $this->NDEF3,
            'NDEF4' => $this->NDEF4,
            'NDEF5' => $this->NDEF5,
            'POSTYDRSCOUNT' => $this->POSTYDRSCOUNT,
            'POSTSDRSCOUNT' => $this->POSTSDRSCOUNT,
            'DR' => $this->DR,
        ]);

        $query->andFilterWhere(['like', 'PK_ORG', $this->PK_ORG])
            ->andFilterWhere(['like', 'PK_GROUP', $this->PK_GROUP])
            ->andFilterWhere(['like', 'PK_ORG_V', $this->PK_ORG_V])
            ->andFilterWhere(['like', 'PK_POST', $this->PK_POST])
            ->andFilterWhere(['like', 'CREATOR', $this->CREATOR])
            ->andFilterWhere(['like', 'CREATIONTIME', $this->CREATIONTIME])
            ->andFilterWhere(['like', 'MODIFIER', $this->MODIFIER])
            ->andFilterWhere(['like', 'MODIFIEDTIME', $this->MODIFIEDTIME])
            ->andFilterWhere(['like', 'VAPPROVEID', $this->VAPPROVEID])
            ->andFilterWhere(['like', 'DAPPROVEDATE', $this->DAPPROVEDATE])
            ->andFilterWhere(['like', 'VAPPROVENOTE', $this->VAPPROVENOTE])
            ->andFilterWhere(['like', 'BILLCODE', $this->BILLCODE])
            ->andFilterWhere(['like', 'TRANSTYPE', $this->TRANSTYPE])
            ->andFilterWhere(['like', 'TRANSTYPEID', $this->TRANSTYPEID])
            ->andFilterWhere(['like', 'PK_BILLTYPE', $this->PK_BILLTYPE])
            ->andFilterWhere(['like', 'PK_BUSITYPE', $this->PK_BUSITYPE])
            ->andFilterWhere(['like', 'PK_DEF1', $this->PK_DEF1])
            ->andFilterWhere(['like', 'PK_DEF2', $this->PK_DEF2])
            ->andFilterWhere(['like', 'PK_DEF3', $this->PK_DEF3])
            ->andFilterWhere(['like', 'PK_DEF4', $this->PK_DEF4])
            ->andFilterWhere(['like', 'PK_DEF5', $this->PK_DEF5])
            ->andFilterWhere(['like', 'VVDEF1', $this->VVDEF1])
            ->andFilterWhere(['like', 'VVDEF2', $this->VVDEF2])
            ->andFilterWhere(['like', 'VVDEF3', $this->VVDEF3])
            ->andFilterWhere(['like', 'VVDEF4', $this->VVDEF4])
            ->andFilterWhere(['like', 'VVDEF5', $this->VVDEF5])
            ->andFilterWhere(['like', 'VVDEF6', $this->VVDEF6])
            ->andFilterWhere(['like', 'VVDEF7', $this->VVDEF7])
            ->andFilterWhere(['like', 'VVDEF8', $this->VVDEF8])
            ->andFilterWhere(['like', 'VVDEF9', $this->VVDEF9])
            ->andFilterWhere(['like', 'VVDEF10', $this->VVDEF10])
            ->andFilterWhere(['like', 'VVDEF11', $this->VVDEF11])
            ->andFilterWhere(['like', 'VVDEF12', $this->VVDEF12])
            ->andFilterWhere(['like', 'VVDEF13', $this->VVDEF13])
            ->andFilterWhere(['like', 'VVDEF14', $this->VVDEF14])
            ->andFilterWhere(['like', 'VVDEF15', $this->VVDEF15])
            ->andFilterWhere(['like', 'DDEF1', $this->DDEF1])
            ->andFilterWhere(['like', 'DDEF2', $this->DDEF2])
            ->andFilterWhere(['like', 'DDEF3', $this->DDEF3])
            ->andFilterWhere(['like', 'DDEF4', $this->DDEF4])
            ->andFilterWhere(['like', 'DDEF5', $this->DDEF5])
            ->andFilterWhere(['like', 'BDEF1', $this->BDEF1])
            ->andFilterWhere(['like', 'BDEF2', $this->BDEF2])
            ->andFilterWhere(['like', 'BDEF3', $this->BDEF3])
            ->andFilterWhere(['like', 'BDEF4', $this->BDEF4])
            ->andFilterWhere(['like', 'BDEF5', $this->BDEF5])
            ->andFilterWhere(['like', 'POSTCODE', $this->POSTCODE])
            ->andFilterWhere(['like', 'POSTNAME', $this->POSTNAME])
            ->andFilterWhere(['like', 'POSTTYPE', $this->POSTTYPE])
            ->andFilterWhere(['like', 'STARTDATE', $this->STARTDATE])
            ->andFilterWhere(['like', 'RZTJZG', $this->RZTJZG])
            ->andFilterWhere(['like', 'POSTDUTY', $this->POSTDUTY])
            ->andFilterWhere(['like', 'POSTRANK', $this->POSTRANK])
            ->andFilterWhere(['like', 'WORKSTANDARD', $this->WORKSTANDARD])
            ->andFilterWhere(['like', 'KEYDUTYRANK', $this->KEYDUTYRANK])
            ->andFilterWhere(['like', 'ISNOTUSE', $this->ISNOTUSE])
            ->andFilterWhere(['like', 'NOTUSEDATE', $this->NOTUSEDATE])
            ->andFilterWhere(['like', 'NOTUSEMAN', $this->NOTUSEMAN])
            ->andFilterWhere(['like', 'SSORG', $this->SSORG])
            ->andFilterWhere(['like', 'TS', $this->TS]);

        return $dataProvider;
    }
}
